package com.ruoyi.common.core.page

import com.ruoyi.common.utils.MyStringUtils


/**
 * 分页数据
 *
 * @author ruoyi
 */
class PageDomain {
    /** 当前记录起始索引  */
    var pageNum: Int? = null

    /** 每页显示记录数  */
    var pageSize: Int? = null

    /** 排序列  */
    var orderByColumn: String? = null

    /** 排序的方向desc或者asc  */
    private var isAsc = "asc"

    /** 分页参数合理化  */
    var reasonable: Boolean? = true
        get() = field?:true
    val orderBy: String
        get() = if (orderByColumn==null||MyStringUtils.NULLSTR == orderByColumn?.trim { it <= ' ' })
            ""
         else MyStringUtils.toUnderScoreCase(orderByColumn) + " " + isAsc

    fun getIsAsc(): String {
        return isAsc
    }

    fun setIsAsc(isAsc: String) {
        var newIsAsc = isAsc
        if (MyStringUtils.isNotEmpty(newIsAsc)) {
            // 兼容前端排序类型
            if ("ascending" == newIsAsc) {
                newIsAsc = "asc"
            } else if ("descending" == newIsAsc) {
                newIsAsc = "desc"
            }
            this.isAsc = newIsAsc
        }
    }
}
